package mvc.bezier;


import gui.Block;
import gui.CheckboxPanel;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BoxLayout;
import javax.swing.JPanel;


import org.geom.render.Engine2D;


public class BezierBlock extends Block {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	BezierModel curve;
	
	public BezierBlock(String title, BezierModel bezier) {
		super(title);
		this.curve = bezier;
		
		initSwing(bezier);
	}

	@Override
	protected void initControls() {
		super.initControls();
		
		JPanel p = new JPanel();
		BoxLayout layout = new BoxLayout(p, BoxLayout.Y_AXIS);
		
		p.setLayout(layout);
		
		BezierPanelController controller = new BezierPanelController(curve);
		
		CheckboxPanel c = new CheckboxPanel("Curve Points",controller, "CurvePoints");
		p.add(c);
		
		c = new CheckboxPanel("Control Points",controller, "ControlPoints");
		p.add(c);
		
		controlWindow.add(p);
		controlWindow.setLocation(1000, 10);
	}
	
	private void initSwing(BezierModel bezier) {
		
		this.setLayout(new GridBagLayout());
		
		BezierView3D view3D;
		BezierMouseController3D controller3D;
		BezierView2D view2D;
		BezierMouseController2D controller2D;
		
		Dimension dim = new Dimension(380,300);
		
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.weightx = 10;
		c.weighty = 10;
		view2D = new BezierView2D(bezier, Engine2D.X, dim);
		bezier.addView(view2D);
		controller2D = new BezierMouseController2D(bezier, view2D);
		view2D.addMouseController(controller2D);
		addView(view2D, c);

		c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 1;
		c.weightx = 10;
		c.weighty = 10;
		view2D = new BezierView2D(bezier, Engine2D.Y, dim);
		bezier.addView(view2D);
		controller2D = new BezierMouseController2D(bezier, view2D);
		view2D.addMouseController(controller2D);
		addView(view2D, c);
		
		c = new GridBagConstraints();
		c.gridx = 1;
		c.gridy = 0;
		c.weightx = 10;
		c.weighty = 10;
		view2D = new BezierView2D(bezier, Engine2D.Z, dim);
		bezier.addView(view2D);
		controller2D = new BezierMouseController2D(bezier, view2D);
		view2D.addMouseController(controller2D);
		addView(view2D, c);
		
		c = new GridBagConstraints();
		c.gridx = 1;
		c.gridy = 1;
		c.weightx = 10;
		c.weighty = 10;
		view3D = new BezierView3D(bezier, dim);
		bezier.addView(view3D);
		controller3D = new BezierMouseController3D(bezier, view3D);
		view3D.addMouseKeybController(controller3D);
		addView(view3D, c);
	}

	
}
